#ifndef __HSYMBOLTABLE_H__
#define __HSYMBOLTABLE_H__

#include <string>
#include "CACT-Type.h"

// Symbol table entry
struct HSTEntry {
	// id, or name
	std::string id;
	// point to the type in parse tree node
	const cact_type_t *type;
	// last assigned temp number
	uint32_t latn;
	// pointer temp number
	uint32_t pttn;
};

class HSymbolTable {
public:
	static HSymbolTable *root;
private:
	HSymbolTable *_parent;
	std::vector<HSymbolTable *> _children;
	std::vector<HSTEntry> _symbols;
public:
	HSymbolTable(HSymbolTable *parent = nullptr) { _parent = parent; }
	HSymbolTable *parent() const { return _parent; }
	std::vector<HSTEntry> &symbols() { return _symbols; }
	HSTEntry &symbol(size_t idx) { return _symbols.at(idx); }
	const std::vector<HSymbolTable *> &children() const { return _children; }
	HSymbolTable *add_child();
	size_t add_symbol(const std::string &id, const cact_type_t *type);
	size_t search_symbol(const std::string &id,
		HSymbolTable * &psymtb, int recur = 1) const;
};

#endif